package br.gov.cemaden.library.model.pcds;

import br.gov.cemaden.library.interfaces.MunicipioInterface;
import br.gov.cemaden.library.interfaces.PosicaoInterface;
import br.gov.cemaden.library.interfaces.pcds.EstacaoInterface;
import br.gov.cemaden.library.interfaces.pcds.RedeInterface;
import br.gov.cemaden.library.interfaces.pcds.TipoEstacaoInterface;

/**
 *
 * @author alan
 * 
 * @Entity
 * @Table(name = "pcds_estacao", schema = "pcds")
 * @SequenceGenerator(name = "sequence", sequenceName = "pcds.pcds_estacao_sequence", schema = "pcds")
 */
public abstract class BaseEstacao implements EstacaoInterface {
    
    /**
     * @Id
     * @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
     * @Column(name="id_estacao", nullable = false, unique = true)   
     */
    protected Long id;
    
    /**
     * @Column(name = "codestacao")
     */
    protected String codigo;
    
    protected Double latitude;
    
    protected Double longitude;
    
    protected Short status;
    
    protected String nome;
        
    /**
     * @ManyToOne(optional = false)
     * @JoinColumn(name="id_municipio", referencedColumnName = "id_municipio")
     */
    protected MunicipioInterface municipio;
    
    /**
     * @ManyToOne(optional = false)
     * @JoinColumn(name = "id_posicao", referencedColumnName = "id_posicao")
     */
    protected PosicaoInterface posicao;
        
    /**
     * @ManyToOne(optional = false)
     * @JoinColumn(name = "id_rede", referencedColumnName = "id_rede")
     */
    protected RedeInterface rede;
    
    /**
     * @ManyToOne(optional = false)
     * @JoinColumn(name = "id_tipoestacao", referencedColumnName = "id_tipoestacao")
     */
    protected TipoEstacaoInterface tipoEstacao;    

    public BaseEstacao() 
    {
    }

    /**
     * @param id the id_estacao to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param codigo the codBaseEstacao to set
     */
    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    /**
     * @param latitude the latitude to set
     */
    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    /**
     * @param longitude the longitude to set
     */
    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(Short status) {
        this.status = status;
    }

    /**
     * @param nome the nome to set
     */
    public void setNome(String nome) {
        this.nome = nome;
    }         

    /**
     * @param municipio the municipio to set
     */
    public void setMunicipio(MunicipioInterface municipio) {
        this.municipio = municipio;
    }
    
    /**
     * @param posicao the posicao to set
     */
    public void setPosicao(PosicaoInterface posicao) {
        this.posicao = posicao;
    }

    /**
     * @param rede the rede to set
     */
    public void setRede(RedeInterface rede) {
        this.rede = rede;
    }

    /**
     * @param tipoEstacao the tipoBaseEstacao to set
     */
    public void setTipoEstacao(TipoEstacaoInterface tipoEstacao) {
        this.tipoEstacao = tipoEstacao;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId()!= null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof BaseEstacao)) {
            return false;
        }
        BaseEstacao other = (BaseEstacao) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return String.format("Estacao:{codigo: %s, nome: %s, latitude: %f, longitude: %f}", 
                getCodigo(), getNome(), getLatitude(), getLongitude());
    }
    
}
